#!/usr/bin/python
# -*- coding: utf-8 -*-

# @File        :   weather_info.py
# @Version     :   1.0
# @Author      :   zhfnss
# @Email       :   mklv2005@163.com
# @Time        :   2021/03/29 21:06:24
# Description  :   

from datetime import datetime

from sqlalchemy import Column, Numeric, Date, String, Integer, Index, UniqueConstraint
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class WeatherInfo(Base):
    __tablename__ = 'weather_info'
    id = Column(Integer, primary_key=True, autoincrement=True)
    # 城市编码
    city_id = Column(Integer, index = True)
    # 日期
    weather_date = Column(String(10))
    # 星期
    weather_week = Column(Integer)
    # 最高温
    high_temp = Column(Numeric(10,2))
    # 最低温
    low_temp = Column(Numeric(10,2))
    # 天气
    weather = Column(Integer)
    # 风力风向
    wind_dir = Column(String(32))
    # PM2.5浓度（μg/m³）
    pm25 = Column(Numeric(10, 2))
    # 空气质量指数
    aqi = Column(String(32))
    # 创建时间
    gmt_create = Column(Date(), default=datetime.now)
    # 最后操作时间
    gmt_modified = Column(Date(), onupdate=datetime.now)

    __table_args__ = (
        UniqueConstraint('city_id', 'weather_date', name='UNIQUE_WEATHER_INFO_CITY_ID'),
        Index('WEATHER_IDX_WEATHER_DATE', 'weather_date')
    )

    def __repr__(self):
        return 'WeatherInfo(id={}, city_id={}, date={}, week={}, high_temp={}, low_temp={}, weather={}, wind_dir={}, pm25={}, aqi={}, gmt_create={}, gmt_modified={})'.format(
            self.id, self.city_id, self.weather_date, self.weather_week, self.high_temp, self.low_temp, self.weather, self.wind_dir, self.pm25, self.aqi, self.gmt_create, self.gmt_modified 
        )

